package cn.iocoder.yudao.module.system.service.zkdatanewrecord;

import org.springframework.stereotype.Service;
import javax.annotation.Resource;
import org.springframework.validation.annotation.Validated;
import org.springframework.transaction.annotation.Transactional;

import java.util.*;
import cn.iocoder.yudao.module.system.controller.admin.zkdatanewrecord.vo.*;
import cn.iocoder.yudao.module.system.dal.dataobject.zkdatanewrecord.ZkdataNewRecordDO;
import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.framework.common.pojo.PageParam;
import cn.iocoder.yudao.framework.common.util.object.BeanUtils;

import cn.iocoder.yudao.module.system.dal.mysql.zkdatanewrecord.ZkdataNewRecordMapper;

import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception;
import static cn.iocoder.yudao.module.system.enums.ErrorCodeConstants.*;

/**
 * 数据项 Service 实现类
 *
 * @author hzx
 */
@Service
@Validated
public class ZkdataNewRecordServiceImpl implements ZkdataNewRecordService {

    @Resource
    private ZkdataNewRecordMapper zkdataNewRecordMapper;

    @Override
    public Long createZkdataNewRecord(ZkdataNewRecordSaveReqVO createReqVO) {
        // 插入
        ZkdataNewRecordDO zkdataNewRecord = BeanUtils.toBean(createReqVO, ZkdataNewRecordDO.class);
        zkdataNewRecordMapper.insert(zkdataNewRecord);
        // 返回
        return zkdataNewRecord.getId();
    }

    @Override
    public void updateZkdataNewRecord(ZkdataNewRecordSaveReqVO updateReqVO) {
        // 校验存在
        validateZkdataNewRecordExists(updateReqVO.getId());
        // 更新
        ZkdataNewRecordDO updateObj = BeanUtils.toBean(updateReqVO, ZkdataNewRecordDO.class);
        zkdataNewRecordMapper.updateById(updateObj);
    }

    @Override
    public void deleteZkdataNewRecord(Long id) {
        // 校验存在
        validateZkdataNewRecordExists(id);
        // 删除
        zkdataNewRecordMapper.deleteById(id);
    }

    private void validateZkdataNewRecordExists(Long id) {
        if (zkdataNewRecordMapper.selectById(id) == null) {
            throw exception(ZKDATA_NEW_RECORD_NOT_EXISTS);
        }
    }

    @Override
    public ZkdataNewRecordDO getZkdataNewRecord(Long id) {
        return zkdataNewRecordMapper.selectById(id);
    }

    @Override
    public PageResult<ZkdataNewRecordDO> getZkdataNewRecordPage(ZkdataNewRecordPageReqVO pageReqVO) {
        return zkdataNewRecordMapper.selectPage(pageReqVO);
    }

}